package com.hhs.FileUpload.util;



import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;
import lombok.experimental.Accessors;

@Setter
@Getter
@ToString
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public final class JsonResult<T> {

    private static final String SUCCESS_MSG = "success";
    private static final String ERROR = "error";

    private static final Integer SUCCESS = 200;
    private static final Integer FAIL = 500;

    private T data;

    private Integer code;

    private String message;

    public JsonResult() {
    }

    private JsonResult(Integer code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> JsonResult<T> success() {
        return new JsonResult<>(SUCCESS, null, SUCCESS_MSG);
    }

    public static <T> JsonResult<T> success(T t) {
        return new JsonResult<>(SUCCESS, t, SUCCESS_MSG);
    }

    public static <T> JsonResult<T> error() {
        return new JsonResult<>(FAIL, null, ERROR);
    }

    public static <T> JsonResult<T> error(String msg) {
        return new JsonResult<>(FAIL, null, msg);
    }

}
